"""
演示文件操作综合案例：文件备份
"""

# 打开文件得到文件对象，准备读取
fr = open("E:/storage/study/Python/python-learn/day01/02-python-learn/08_文件操作/素材/bill.txt", "r", encoding="UTF-8")
# 打开文件得到文件对象，准备写入
fw = open("E:/storage/study/Python/python-learn/day01/02-python-learn/08_文件操作/素材/bill.txt.bak", "w", encoding="UTF-8")
# for循环读取文件
for lineR in fr:
    word = lineR.strip().split(",")[4];
    # 判断内容，将满足的内容写出
    if(word == "测试") :
        continue # continue进入下一次循环，这一次后面的内容就跳过了
    # 将内容写出去
    fw.write(lineR)
    # 由于前面对内容进行了strip()的操作，所以要手动的写出换行符
    fw.write("\n")
# close 2个文件对象
fw.close()
fr.close()